{% extends 'TopxiaWebBundle:CourseManage:layout.html.twig' %}

{% block title %}{{'试卷题目管理'|trans}} - {{ parent() }}{% endblock %}

{% set side_nav = 'testpaper' %}
{% set script_controller = 'testpaper/item-manager' %}

{% block main %}

<style>
tr.placeholder {
  display: block;
  background: red;
  position: relative;
  margin: 0;
  padding: 0;
  border: none;
}
tr.placeholder:before {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
    border: 5px solid transparent;
    border-left-color: red;
    margin-top: -5px;
    left: -5px;
    border-right: none;
}
</style>

<div class="panel panel-default panel-col" id="testpaper-items-manager">
  <div class="panel-heading">
    {{testpaper.name}}
  </div>

  <div class="panel-body clearfix">

    <ol class="breadcrumb">
        <li><a href="{{ path('course_manage_testpaper',{courseId:course.id}) }}">{{'试卷管理'|trans}}</a></li>
        <li class="active">{{'试卷题目管理'|trans}}</li>
    </ol>

    <div class="clearfix mbm">
      <button data-url="{{ path('course_manage_testpaper_item_picker',{courseId:course.id, testpaperId:testpaper.id}) }}" class="btn btn-info btn-sm pull-right" data-role="pick-item"><span class="glyphicon glyphicon-plus"></span> {{'新增试题'|trans}}</button>
      <ul class="nav nav-pills nav-mini">
        {% for type in testpaper['metas']['question_type_seq'] %}
          <li><a href="javascript:" data-type="{{ type }}" data-name="{{ dict_text('questionType', type) }}" class="testpaper-nav-link">{{ dict_text('questionType', type) }}</a></li>
        {% endfor %}
      </ul>
    </div>

    <form  method="post" id="testpaper-items-form" class="form-horizontal">
      <div id="testpaper-stats" class="text-success"></div>
      <table class="table table-striped table-hover tab-content" id="testpaper-table">
        <thead>
          <tr>
            <th></th>
            <th><input type="checkbox" data-role="batch-select"></th>
            <th>{{'题号'|trans}}</th>
            <th width="40%">{{'题干'|trans}}</th>
            <th>{{'类型'|trans}}</th>
            <th>{{'难度'|trans}}</th>
            <th width="8%">{{'分值'|trans}}</th>
            <th>{{'操作'|trans}}</th>
          </tr>
        </thead>

        {% for type, typeItems in items %}
          <tbody data-type="{{ type }}" id="testpaper-items-{{ type }}" class="hide testpaper-table-tbody">
            {% for item in typeItems %}
              {% set question = questions[item.questionId] %}
              {% include 'TopxiaWebBundle:CourseTestpaperManage:item-tr.html.twig' %}
              {% if subItems[item.questionId]|default(null) %}
                {% for item in subItems[item.questionId] %}
                  {% set question = questions[item.questionId] %}
                  {% include 'TopxiaWebBundle:CourseTestpaperManage:item-tr.html.twig' %}
                {% endfor %}
              {% endif %}
            {% endfor %}
          </tbody>
        {% endfor %}
      </table>

      <div>
        <label class="checkbox-inline"><input type="checkbox" data-role="batch-select"> {{'全选'|trans}}</label>
        <button type="button" class="btn btn-default btn-sm mlm" data-role="batch-delete"  data-name="{{'题目'|trans}}">{{'删除'|trans}}</button>
      </div>

      <div class="form-group">
        <div class="col-md-8 controls">
          <div class="passedScoreDiv" {% if hasEssay %}style="display:none"{% endif %}>这是一份纯客观题的试卷, 达到 <input type="text" name="passedScore" class="form-control width-input width-input-small" value="{{ passedScoreDefault }}" data-score-total="0" />分（含）可以自动审阅通过考试。</div>
        </div>
        <div class="col-md-4 controls">
          <button type="button" class="btn btn-primary pull-right mlm request-save">{{'保存'|trans}}</button>
        </div>
      </div>


      <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
    </form>
  </div>

  <div id="testpaper-confirm-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">{{'确认试卷题目信息'|trans}}</h4>
        </div>
        <div class="modal-body">
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>{{'题目类型'|trans}}</th>
                <th>{{'题目数量'|trans}}</th>
                <th>{{'总分值'|trans}}</th>
              </tr>
            </thead>
            <tbody class="detail-tbody"></tbody>
          </table>

        </div>
        <div class="modal-footer">
          <button class="btn btn-link" data-dismiss="modal" type="button">关闭</button>
          <button type="button" class="btn btn-primary confirm-submit" data-saving-text="{{'正在保存'|trans}}...">{{'确定'|trans}}</button>
        </div>
      </div>
    </div>
  </div>

  <script type="text/x-handlebars-template" data-role="confirm-tr-template">
    {% verbatim %}
      <tr>
        <td>{{name}}</td>
        <td>{{count}}题</td>
        <td>{{score}}分</td>
      </tr>
    {% endverbatim %}
  </script>

</div>





{% endblock %}